package songzan.lalala;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;


/**
 * Hello world!
 *
 */
/**
 * @author JSJSYS
 *
 */
@SpringBootApplication
@Controller
public class App 
{
	public static Map<String,adminInfo> map = new HashMap<String,adminInfo>();
	@RequestMapping("/admin")
	public String adminInfo(Model model) {
		List<adminInfo>list = new ArrayList<adminInfo>();
		for(Map.Entry<String,adminInfo> entry : map.entrySet()) {
			list.add(entry.getValue());
		}
		model.addAttribute("admins",list);
		model.addAttribute("size",list.size());	
     	return "user/admin-role";	
	}
	@RequestMapping("/home")
    @ResponseBody
	public String home()
	{
		return "xxx";		
	} 
	
	@RequestMapping("test1")
	public String test1(){
		return "eee";		
	}
	@RequestMapping("test2")
	@ResponseBody
	public String test2(){
     RestTemplate restTemplate = new RestTemplate();
		
		String result = restTemplate.getForObject("https://www.baidu.com",String.class);
		
		return result;
		
	}
	@RequestMapping("/adduser")
	public String adduser(HttpServletRequest request,Model model) {
		String id = request.getParameter("id");
		if("".equals(id) || null == id) {
		    return "/user/admin-role-add";
		}else {
			adminInfo admin = map.get(id);
			model.addAttribute("admin",admin);
			return "/user/admin-role-add";
			}
		  

	}
	
	


public static void main( String[] args )
{
    	  SpringApplication.run(App.class, args);

 }
}
